package com.example.listviewtest;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    ListView listView;
    Button jumpToRecyclerActivity;
    ArrayList<Animal> data = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        createData();
        listView = findViewById(R.id.listView);
//        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,data);
        AnimalAdapter arrayAdapter = new AnimalAdapter(this,R.layout.animal,data);
        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getApplicationContext(),"position:"+position,Toast.LENGTH_SHORT).show();
            }
        });
        jumpToRecyclerActivity = findViewById(R.id.jumpToRecyclerActivity);
        jumpToRecyclerActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent  = new Intent(MainActivity.this,RecyclerActivity.class);
                startActivity(intent);
            }
        });
    }

    private void createData() {
        for(int i = 0; i < 100; i++){
            Animal animal = new Animal(R.drawable.animal,String.valueOf(i));
            data.add(animal);
        }
    }
}